package com.huice.base;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.Message.RecipientType;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class Mailer {

	public static void sendMail(String text) {
		try {
			Properties p = new Properties();
			p.setProperty("mail.smtp.host", "smtp.163.com");
			p.setProperty("mail.smtp.port", "25");
			p.setProperty("mail.smtp.auth ", "true");
			p.setProperty("mail.transport.protocol", "smtp");
			Session session = Session.getInstance(p);
			
			Message message = new MimeMessage(session);
			message.setRecipient(RecipientType.TO, new InternetAddress("747781867@qq.com"));
			message.setContent(text, "text/html;charset=UTF-8");
			message.setSubject("测试邮件");
			message.setFrom( new InternetAddress("zach_lau@163.com","自动化测试组"));
			
			Transport transport = session.getTransport();
			transport.connect("smtp.163.com","zach_lau","");
			transport.sendMessage(message, message.getAllRecipients());
			transport.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
